Page 1 of 1
PDO and submit buttons
Posted: Tue Apr 01, 2014 1:04 pm
by nite4000
Hey everyone. I am learning PDO and as I can see its can be confusing for anyone starting out.
I am rewriting some code I have and one form is a signup form and I need to use a button however its like the pdo don't like the button
Here is what I have
Code: Select all
if(strlen($_POST['go']))
{
$ticket ='1234';
$status ='Open';
try
{
$stmt = ("INSERT INTO sites (id,ticketnumber, status) VALUES (:null, :ticketnumber, :status)");
$stmt = $conn->prepare($stmt);
$stmt->bindValue(':ticketnumber', $ticket, PDO::PARAM_INT);
$stmt->bindValue(':status', $status, PDO::PARAM_STR);
$stmt->execute();
echo $stmt;
}
catch(PDOException $e)
{
$e->getmessage();
}
}
this is sample code I am practicing with first . I get no errors but if I remove the if submit code it will work on page load.
any help or ideas would be great
Re: PDO and submit buttons
Posted: Tue Apr 01, 2014 1:51 pm
by requinix
PDO doesn't care about the submit button. Completely unrelated.
What does your form look like?
Re: PDO and submit buttons
Posted: Tue Apr 01, 2014 1:58 pm
by nite4000
Code: Select all
<form action="register.php" method="post">
<table width="548" align="center" class="tbl">
<tr>
<td width="123">Username :</td>
<td width="413"><input name="usr" type="text" class="username" size="32" maxlength="50" value="Username" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}" /></td>
</tr>
<tr>
<td>Password :</td>
<td><input name="psw" type="password" class="password" size="32" maxlength="32" value="Password" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>First Name :</td>
<td><input name="fn" type="text" class="fnln" id="fn" size="32" maxlength="50" value="First Name" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>Last Name :</td>
<td><input name="ln" type="text" class="fnln" id="ln" size="32" maxlength="50" value="Last Name" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>City :</td>
<td><input name="cty" type="text" class="city" id="cty" size="32" maxlength="50" value="City" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>State/Province :</td>
<td><input name="st" type="text" class="state" id="st" size="32" maxlength="50" value="State" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>Country :</td>
<td><input name="ctry" type="text" class="country" id="ctry" size="32" maxlength="50" value="Country" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>Email :</td>
<td><input name="email" type="text" class="email" id="email" size="32" maxlength="50" value="my@email.com" onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"/></td>
</tr>
<tr>
<td>Secret Password :</td>
<td><input name="secpsw" type="password" id="secpsw" size="32" maxlength="50"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Verification Code :</td>
<td><input type="text" name="code" id="code" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="go" value="Register" id="go" /></td>
</tr>
</table></form>
Re: PDO and submit buttons
Posted: Tue Apr 01, 2014 2:57 pm
by Christopher
Since you don't set the ID:
Code: Select all
$stmt = ("INSERT INTO sites (id,ticketnumber, status) VALUES (NULL, :ticketnumber, :status)");
Re: PDO and submit buttons
Posted: Tue Apr 01, 2014 6:31 pm
by nite4000
I'm afraid that didn't help no record was inserted
Re: PDO and submit buttons
Posted: Tue Apr 01, 2014 7:17 pm
by Celauran
nite4000 wrote:
Code: Select all
catch(PDOException $e)
{
$e->getmessage();
}
}
this is sample code I am practicing with first . I get no errors
You have to actually echo the message.