PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Tue Apr 01, 2014 1:04 pm
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
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Apr 01, 2014 1:51 pm
PDO doesn't care about the submit button. Completely unrelated.
What does your form look like?
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Tue Apr 01, 2014 1:58 pm
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>
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Apr 01, 2014 2:57 pm
Since you don't set the ID:
Code: Select all
$stmt = ("INSERT INTO sites (id,ticketnumber, status) VALUES (NULL, :ticketnumber, :status)");
(#10850)
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Tue Apr 01, 2014 6:31 pm
I'm afraid that didn't help no record was inserted
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Apr 01, 2014 7:17 pm
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.