Jump to content

Recommended Posts

I am trying to submit a form and then run an update but its not working, please help

 

here is my page:

 

<?php
session_start();

mysql_connect("xxx", "xxx", "xxx");
mysql_select_db("xxx");

$id = $_REQUEST['id'];

$query1 = "SELECT * FROM app1_blog";
$result1 = mysql_query($query1);

$qry="SELECT id,title,date,article,image1,image2,image3 FROM app1_blog WHERE id = '$id'";
$cur=mysql_query($qry);
while($i=mysql_fetch_row($cur))
{$id=$i[0];
$title=$i[1];
$date=$i[2];
$article=$i[3];
$image1=$i[4];
$image2=$i[5];
$image3=$i[6];
}





if(isset($_POST['submit'])){
echo 'hello';
$new_title=mysql_real_escape_string(stripslashes($_POST["title"]));
$new_article=mysql_real_escape_string(stripslashes($_POST["article"]));
echo $new_title;
}
//$sql = "UPDATE app1_blog SET title='$new_title',article='$new_article' WHERE id = '$id'";

//$msg = 'Blog edited';
//$result = mysql_query($sql,$link) or die('Error: ' . mysql_error() . '<br>SQL: ' . $sql);

//header("Location: edit.php?msg=$msg&id=$id");

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <title></title>
 
 
 
  <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
 
  <!-- Extra Codiqa features -->
  <link rel="stylesheet" href="codiqa.ext.css">
 
  <!-- jQuery and jQuery Mobile -->
  <script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
  <script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

  <!-- Extra Codiqa features -->
  <script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>
   
</head>

<body>
<!-- Home -->
<div data-role="page" id="page<?php echo $id;?>">
    <div data-theme="a" data-role="header">
        <h3>
            Edit blog post
        </h3>
    </div>
    <div data-role="content">
        <h2>
            Blog
        </h2>
        <form method="post" action="<?php print $_SERVER["PHP_SELF"]; ?>" name="form">
        <div data-role="fieldcontain">
            <label for="textinput1">
                Title
            </label>
            <input name="title" id="textinput1" placeholder="" value="<?php echo $title;?>" type="text">
            <input name="id" placeholder="" value="<?php echo $id;?>" type="hidden">
        </div>
        <div data-role="fieldcontain">
            <label for="textinput2">
                Date
            </label>
            <input name="date" id="textinput2" placeholder="" value="<?php echo $date;?>" type="text">
        </div>
        <div data-role="fieldcontain">
            <label for="textinput3">
                Article
            </label>
            <textarea name="article" id="textarea1" placeholder=""><?php echo $article;?></textarea>
        </div>
            <img src="<?php echo $image1;?>" alt="image" width="288" >
            <img src="<?php echo $image2;?>" alt="image" width="288" >
            <img src="<?php echo $image3;?>" alt="image" width="288" >
        <input data-theme="b" value="Submit" type="submit">
        </form>
    </div>
</div>
</body>
</html>

i would guess your current problems is that you are redirecting at some point in the code and any output you might be sending is being buffered and discarded so you never see it.

 

two things -

 

1) you need to make sure output_buffering is turned off in your php.ini

2) comment out any header() redirects until after you get your code to do what you want.

if(isset($_POST['submit']) && 'submit' === $_POST['submit'])
{
 echo 'hello';
 ..............
 ..............
 ..............
}
else
{
 echo 'hi'
}

try sample one, above.. if the output is "hi". your post is working else your code inside the open parenthesis are wrong.. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.